<?php

namespace app\index\controller;

use think\Controller;
use think\Container as Containers;

class Container extends Controller
{

    /**
     * User : 咔咔
     * Notes:
     * Time :2020/9/23 21:28
     * @route('testContainer');
     */
    public function testContainer ()
    {
        // $data = Config::get('app.');
        $data = Containers::get('config')->get('app.');
        dump($data);die;
    }

    /**
     * User : 咔咔
     * Notes: 玩转自己的容器类
     * Time :2020/9/21 21:35
     * @route('dependency');
     */
    public function dependency()
    {
        // $person = new Person();
        // $obj = new Car();
        // var_dump($person->buy($obj));die;

        // \container\Container::getInstance()  返回的是Container实例
        \container\Container::getInstance()->set('person','container\dependency\Person');
        \container\Container::getInstance()->set('car','container\dependency\Car');
        $obj = \container\Container::getInstance()->get('person');
        dump($obj->buy());die;
    }

    /**
     * Container容器类剖析之Countable巧用案例
     * @route('countable');
     */
    public function countable ()
    {
        $arr2 = array('apple', 'banana', array('cat', 'camel'), 'dog');
        $val2_1 = count($arr2);
        $val2_2 = count($arr2, 1);
        dump($val2_1."----".$val2_2);die;
        //$data = [1,2,3];
        // /dump(count($data));die;
        $countable = new \container\countableTest();
        for ($i = 0; $i < 10; ++$i) {
            echo "I have been count()ed " . count($countable) . " times\n";
        }
    }

}
